package com.example.demos.controller;

import java.util.Scanner; 

/*
 * 计算器
 */
public class Calculator {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		//固定打印语句---请按照提示语句进行操作
		System.out.println("请选择您所需要使用的功能\n"
				+ "1.计算器\n"
				+ "2.判断xxxx年xx月共有多少天\n"
				+ "3.计算1+2+3+...+100的值\n"
				+ "4.计算1+1/2+1/3+...+1/100的值");
		int choose = scanner.nextInt();
		
		switch(choose) {
		case 1:
			System.out.println("计算器程序运行");
			while(true) {
				System.out.println("输入你要计算的值：");
				double num = scanner.nextDouble();
				double num1 = scanner.nextDouble();
				System.out.println("输入你要计算的方式：");
				String operator = scanner.next();
				
				if("+".equals(operator)) {
					System.out.println(num + "+" + num1 + "=" + (num + num1));
				}else if("-".equals(operator)) {
					System.out.println(num + "-" + num1 + "=" + (num + num1));
				}else if("*".equals(operator)) {
					System.out.println(num + "*" + num1 + "=" + (num + num1));
				}else if("/".equals(operator)) {
					System.out.println(num + "/" + num1 + "=" + (num + num1));
				}else if("%".equals(operator)) {
					System.out.println(num + "%" + num1 + "=" + (num + num1));
				}else {
					System.out.println("您的输入有误，程序退出");
					break;
				}
				System.out.println("计算完毕，重新计算请按y，任意键退出");
				String character = scanner.next();
				if("y".equals(character)) {
					System.out.println("程序重新运行");
				}else {
					System.out.println("程序退出");

				}
			}
			
		case 2:
			System.out.println("判断xxxx年xx月共有多少天\\n");
			System.out.println("输入年份:");
			int year = scanner.nextInt();
			System.out.println("输入月份:");
			int month = scanner.nextInt();
			int days = 0;
			
				switch(month) {
					case 1:
					case 3:
					case 5:
					case 7:
					case 8:
					case 10:
					case 12:
						days = 31;
						break;
						
					case 4:
					case 6:
					case 9:
					case 11:
						days = 30;
						break;
					case 2:
						if(year % 4 == 0 && year % 100 != 0 && year % 400 == 0) {
							days = 29;
						}else {
							days = 28;
						}
						break;
						
						default:
							break;//待定
				}
				
		}

	}
}
